package com.example.sys.calendar.controller;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.core.controller.BaseController;
import com.example.sys.calendar.service.SysCalendarService;
import com.example.sys.calendar.vo.SysCalendarVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("sysCalendar")
@RestController
public class SysCalendarController extends BaseController<SysCalendarService, SysCalendarVo> {
    @Override
    public QueryWrapper changeFindPageQueryWrapper(SysCalendarVo vo) {
        QueryWrapper<SysCalendarVo> queryWrapper = super.changeFindPageQueryWrapper(vo);
        if (StringUtils.isNotEmpty(vo.getNowDay())) {
            queryWrapper.and(wrapper -> wrapper.le("start_time", DateUtil.parse(vo.getNowDay(), DatePattern.NORM_DATE_PATTERN)))
                    .and(wrapper -> wrapper.ge("end_time", DateUtil.parse(vo.getNowDay(), DatePattern.NORM_DATE_PATTERN)));
        }
        return queryWrapper;
    }
}
